package cn.com.jenson.common;

import cn.com.jenson.util.SystemUtil;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.SystemUtils;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.Objects;

/**
 * BasicEntity<br>
 * Entity公共类
 */
@Getter
@Setter
@MappedSuperclass
@DynamicUpdate
public abstract class BasicEntity implements Serializable {

    /**
     * id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    /**
     * 是否删除
     */
    private Boolean deleted = false;
    /**
     * 作者Id
     */
    private String authorId;
    /**
     * 创建时间
     */
    private Date createdDate;
    /**
     * 修改时间
     */
    private Date updatedDate;

    /**
     * 创建时事件
     */
    @PrePersist
    private void setCreated() {
        createdDate = new Date();
        updatedDate = new Date();
        authorId = SystemUtil.getLoginUser();
    }

    /**
     * 修改时事件
     */
    @PreUpdate
    private void setUpdate(){
        updatedDate = new Date();
        authorId = SystemUtil.getLoginUser();
    }
}
